<!--
 * @Author: MrLee
 * @Date: 2024-09-03 11:05:16
 * @LastEditors: MrLee
 * @LastEditTime: 2024-09-14 09:34:22
 * @Description: 请填写简介
-->
<template>
  <view class="px-24rpx">
    <view class="shadow-[0px_3px_6px_0px_rgba(235,235,235,0.30)] rounded-[22px] bg-#fff py-28rpx px-26rpx] pb-40rpx mb-40rpx">
    <view class="flex justify-between items-center text-[#333] text-[26rpx]">
      <view class="flex items-center">在招职位<span @click="recp" class="text-[#1664FF] px-4rpx">{{jobOpenCount}}</span>个<view class="iconfont icon-youjiantou text-[#333]"></view></view>
      <view @click="jump('/pages/common/post-position/index')" class="flex items-center">
        <view class="">➕</view>
        <view>发布职位</view>
      </view>
    </view>
    <view class="flex justify-between items-center text-[#1d2129] text-[26rpx] mt-62rpx">
      <view @click="jump('/pages/enterprise/resume-warehouse/index')">
        <image class="w-104rpx h-104rpx mb-8rpx" src="https://yiliao.test03.qcw800.com/static/images/tab/home-q1.png" />
        <view class="text-center">收到简历</view>
      </view>
      <view @click="jump('/pages/enterprise/job-interaction/index')">
        <image class="w-104rpx h-104rpx mb-8rpx" src="https://yiliao.test03.qcw800.com/static/images/tab/home-q2.png" />
        <view class="text-center">职位互动</view>
      </view>
      <view  @click="jump('/pages/enterprise/job-interaction/index')">
        <image class="w-104rpx h-104rpx mb-8rpx" src="https://yiliao.test03.qcw800.com/static/images/tab/home-q3.png" />
        <view class="text-center">感兴趣</view>
      </view>
      <view  @click="jump('/pages/enterprise/recruitmentFunnel/index')">
        <image class="w-104rpx h-104rpx mb-8rpx" src="https://yiliao.test03.qcw800.com/static/images/tab/home-q4.png" />
        <view class="text-center">招聘漏斗</view>
      </view>
    </view>
  </view>
  </view>
  <Tabbar :tab-list="tabList" classLis="rounded-[40rpx_40rpx_0_0]" @click="tabChange"/>
  <view v-for="item, index in resumeList" :key="index" class="mb-32rpx bg-#fff px-54rpx">
      <view class="px-0rpx py-24rpx bg-#f7f9ff text-[#1d2129] text-[26rpx]"
      v-if="item.have_teacher == 1">
        {{item.teacher_school_name}}·{{item.teacher_college_name}}·{{item.teacher_name}}老师推荐
      </view>
      <view class="pb-36rpx pt-18rpx">
        <up-gap height="20rpx" />
        <view class="flex"
        @click="routerToResumeDetail(item.resume_id)">
          <view class="mr-16rpx h-100rpx w-100rpx shrink-0">
            <up-image width="100rpx" height="100rpx" shape="circle"
            :src="item.avatar"/>
          </view>
          <view class="flex-auto">
            <view class="mb-16rpx flex items-center justify-between">
              <view class="text-32rpx color-#1d2129">
                {{item.name}}
              </view>

            </view>
            <view class="flex text-26rpx color-#6e6d72 leading-100%">
              <text>{{item.province}}·{{item.city}}</text>
              <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
              <text>{{item.gender}}</text>
              <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
              <text>{{item.qualification}}</text>
              <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
              <text>{{item.nature}}</text>
            </view>
          </view>
        </view>
        <up-gap height="20rpx" />
        <view class="flex items-center justify-between b-b b-b-#f6f7f8 pb-18rpx">
          <view class="flex items-center"
          @click="routerToResumeDetail(item.resume_id)">
            <view class="mr-10rpx bg-#fcf8e9 px-8rpx color-#f57100 leading-42rpx"
              v-for="highlight in item.highlights">
              {{highlight}}
            </view>
          </view >
          <image class="h-60rpx w-60rpx" :src="item.like_img"
          @click="onclickUserLike(index, item.resume_id, item.like)" />
        </view>
        <up-gap height="20rpx" />
        <view class="flex flex-wrap items-center text-26rpx color-#6e6d72 leading-36rpx"
        @click="routerToResumeDetail(item.resume_id)">
          <text>{{item.school_name}}</text>
          <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
          <text>{{item.college_name}}</text>
          <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
          <text>{{item.status_overseas_study}}</text>
        </view>
        <up-gap height="20rpx" />
        <view class="flex items-center justify-between">
          <view class="flex flex-wrap items-center text-26rpx color-#4e5968 leading-36rpx">
            <text>{{item.heart_content}}</text>
          </view>
          <view>
<!--            <up-copy content="健康体检·临床试验 10k-15k">-->
              <view class="flex items-center">
                <up-button
            :custom-style="{
              width: '144rpx',
              height: '58rpx',
              background: '#1f50f2',
              'border-radius': '60rpx',
              'font-size': '24rpx',
              color: '#ffffff',
              margin: '0',
            }"
            @click="lianxi(item)"
          >
            立即沟通
          </up-button>
              </view>
<!--            </up-copy>-->
          </view>
        </view>
        <view style="border-bottom: 1px solid #ededed;" class="mt-22rpx mb-30rpx"></view>
          <view class="flex items-center"
          v-if="item.have_other_hr == 1">
            <up-image width="42rpx" height="42rpx" shape="circle"
            :src="item.other_hr_avatar"/>
            <view class="text-[#1d2129] text-[26rpx] mr-16rpx">同事 {{item.other_hr_name}}·{{item.other_hr_duty}} 已联系</view>
          </view>
      </view>
    </view>



</template>

<script setup lang="ts">
import Tabbar from '@/pages/components/tabbar/index.vue';
import { hrLookResumeList, userJobInteractionUpdate, userJobType } from '@/api/user';
import {hrTalkING, hrTalkLike, hrTalkNew} from '@/api/user/company';
import { hrChat } from '@/api/user/common';
const home06 = "https://yiliao.test03.qcw800.com/static/images/tab/home-06.png";
const home10 = "https://yiliao.test03.qcw800.com/static/images/tab/home-10.png";

interface Tab {
  id: number;
  name: string;
  activeLineWidth: string;
}
const tabList = reactive<Tab[]>([
  {
    id: 0,
    name: '全部',
    activeLineWidth: '72'
  }
]);

const recp = () => {
  uni.navigateTo({
    url: '/pages/common/recp-positions/index?type=0',
  });
}
const jump = (u:string) => {
  uni.navigateTo({
    url: u,
  });
}

const lianxi = (item) => {
  console.log(item)
  uni.navigateTo({
    url:"/pages/tab/message/details/index?userID=" + item.user_id
  })
}

const routerToResumeDetail = (resume_id: number) => {
  uni.navigateTo({
    url: '/pages/userinfo/resume-HRPerspective?resume_id='+resume_id,
  });
};

const onclickUserLike = async (index:number, resume_id:number, like: number) => {
  console.log('修改职位互动type:::', index, ' job_id:::', resume_id, ' like:::', like);

  const result = await userJobInteractionUpdate({
    like_hr: like == 1? 0 : 1,
    resume_id: resume_id,
  });
  console.log('修改hr互动result:::', result);
  resumeList[index].like_img = like == 1 ? home10 : home06;
  resumeList[index].like = like == 1 ? 0 : 1;
}
const jobOpenCount = ref(0)
const rectiveResumeCount = ref(0)
const resumeList:any = reactive([])
async function getHrLookResumeList(position_id: number) {
  let params:any = {}
  if (position_id != 0) {
    params['position_id'] = position_id;
  }
  resumeList.splice(0, resumeList.length);
  let result = await hrLookResumeList(params);
  console.log('hr查看职位列表 r:::', result);
  if (!result || !result.list) {
    return
  }
  jobOpenCount.value = result.job_open_count
  rectiveResumeCount.value = result.rective_resume_count
  for (let i = 0; i < result.list.length; i++) {
    let r = result.list[i]
    let rr = {
      resume_id: r.id,
      avatar: r.user.avatar,
      name: r.user.name,
      user_id: r.user.id,
      gender: r.user.gender,
      province: r.intention.province.name,
      city: r.intention.city.name,
      position_type: r.intention.position.p_content,
      position: r.intention.position.content,
      qualification: r.education.qualification,
      nature: r.intention.nature,
      highlights: r.highlights,
      like: r.like,
      like_img: r.like == 1 ? home06 : home10,
      school_name: r.education.school_name,
      college_name: r.education.college_name,
      majors_name: r.education.majors_name,
      status_overseas_study: '',
      heart_content: r.heart_content,
      have_other_hr: !!r.other_hr ? 1 : 0,
      other_hr_name: '',
      other_hr_avatar: '',
      other_hr_duty: '',
      have_teacher: !!r.teacherInfo ? 1 : 0,
      teacher_name: '',
      teacher_school_name: '',
      teacher_college_name: '',

    }
    if (r.status_overseas_study == 1) {
      rr.status_overseas_study = '留学'
    } else {
      rr.status_overseas_study = '未留学'
    }
    if (rr.have_other_hr == 1) {
      rr.other_hr_name = r.other_hr.name
      rr.other_hr_avatar = r.other_hr.avatar
      rr.other_hr_duty = r.other_hr.hr.duty.name
    }
    if (rr.have_teacher == 1) {
      rr.teacher_name = r.teacherInfo.name
      rr.teacher_school_name = r.teacherInfo.teacher.school.name
      rr.teacher_college_name = r.teacherInfo.teacher.college.name
    }
    resumeList.push(rr)
  }
}
async function getJobType() {
  let result = await userJobType();
  console.log('HR首页职位类型::', result);
  for (let i = 0; i < result.length; i++) {
    const r = result[i]
    if (r.level == 2) {
      tabList.push({
        id: r.id,
        name: r.content,
        activeLineWidth: r.content.length * 36+""
      })
    }
  }
  if (tabList.length > 0) {
    getHrLookResumeList(0);
  }
}
function tabChange(item) {
  console.log('点击item:::', item)
  getHrLookResumeList(item.id)
}
onLoad(()=> {
  getJobType()

  //聊天列表测试
  hrChat(38)
  hrTalkNew()
  hrTalkING()
  hrTalkLike()
})
</script>
